package org.dllwh.utils.google.response.handle;

import lombok.Getter;
import lombok.Setter;
import okhttp3.Response;

import java.io.IOException;
import java.nio.charset.Charset;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * <p>
 * Today the best performance as tomorrow the newest starter!
 *
 * @ClassName StringDataHandler
 * @Description 字符串数据处理器
 * @Date 2025-06-12 13:35
 * @版本 V 1.0.1
 * @since JDK 17
 */
public class StringDataHandler implements DataHandler<String> {
    /**
     * 字符编码
     */
    @Getter
    @Setter
    private Charset charset;

    @Override
    public String handle(Response response) throws IOException {
        if (this.charset != null) {
            assert response.body() != null;
            return new String(response.body().bytes());
        }
        return response.body() != null ? response.body().string() : null;
    }
}
